﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace WindowsPhoneApplication1
{
    public partial class SingleUserPage : PhoneApplicationPage
    {
        IDictionary<string, string> parameters;
        public SingleUserPage()
        {
            InitializeComponent();
            Connectors.Connector.Sup = this;
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            parameters = this.NavigationContext.QueryString;
            base.OnNavigatedTo(e);
        }

        public void UpdateDashboardDataSource(List<WebServiceDataSources.Status> statuses)
        {
            Dispatcher.BeginInvoke(() =>
                {
                    UserDashboardListBox.DataContext = statuses;
                });
        }

        private void UserDashboardListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (UserDashboardListBox.SelectedItem != null)
            {
                string statusId = ((WebServiceDataSources.Status)UserDashboardListBox.SelectedItem).id.ToString();
                NavigationService.Navigate(new Uri("/Views/SingleStatusPage.xaml?SID=" + statusId, UriKind.Relative));
                UserDashboardListBox.SelectedItem = null;
            }
        }

        private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(parameters["UID"]))
            {
                PageTitle.Text = parameters["UID"];
                Connectors.UserConnector.GetUserDashboard(parameters["UID"]);
            }
            else if (NavigationService.CanGoBack)
                NavigationService.GoBack();
        }
    }
}
